<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="系部" prop="college">
        <el-input
          v-model="queryParams.college"
          placeholder="请输入系部"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="creditStatus">
        <el-select
          v-model="queryParams.creditStatus"
          placeholder="请选择"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.creditStatus"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="goApply">实践积分申请</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="teamList" @selection-change="handleSelectionChange">
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="团队名称" align="center" prop="teamName" />
      <el-table-column label="系部" align="center" prop="college" />
      <el-table-column
        label="调研主题"
        :formatter="researchtopicFormat"
        align="center"
        prop="researchtopic"
      />
      <el-table-column label="学分" align="center" prop="creditNum" />
      <el-table-column
        label="状态"
        align="center"
        :formatter="creditStatusFormat"
        prop="creditStatus"
      />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            >查看材料</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改团队对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="系部" prop="college">
          <el-input v-model="form.college" placeholder="请输入系部" />
        </el-form-item>
        <el-form-item label="调研主题" prop="researchtopic">
          <el-input v-model="form.researchtopic" placeholder="请输入调研主题" />
        </el-form-item>
        <el-form-item label="是否重点" prop="isimportant">
          <el-input v-model="form.isimportant" placeholder="请输入是否重点" />
        </el-form-item>
        <el-form-item label="呈现形式" prop="presentation">
          <el-input v-model="form.presentation" placeholder="请输入呈现形式" />
        </el-form-item>
        <el-form-item label="呈现形式详情" prop="presentationdetail">
          <el-input v-model="form.presentationdetail" placeholder="请输入呈现形式详情" />
        </el-form-item>
        <el-form-item label="交通费" prop="transportation">
          <el-input v-model="form.transportation" placeholder="请输入交通费" />
        </el-form-item>
        <el-form-item label="住宿费" prop="accommodation">
          <el-input v-model="form.accommodation" placeholder="请输入住宿费" />
        </el-form-item>
        <el-form-item label="宣传费" prop="publicity">
          <el-input v-model="form.publicity" placeholder="请输入宣传费" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 实践积分申请对话框 -->
    <el-dialog title="实践积分申请" :visible.sync="applyopen" width="700px" append-to-body>
      <el-select
		    v-model="upload.college"
		    placeholder="参与团队"
		    clearable
		    size="small"
		    style="width: 240px"
		  >
		    <el-option
		      v-for="dict in teamOptions"
		      :key="dict.id"
		      :label="dict.name"
		      :value="dict.id"
		    />
		  </el-select>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>内容</span>
        </div>
        <ckeditor v-model="purpose" :config="editorConfig0"></ckeditor>
      </el-card>
      <!-- <el-button
        style="margin-top: 20px; float: right"
        type="primary"
        @click="submitFormApply"
        v-hasPermi="['eqxm:teamTeacher:add']"
        >提交</el-button
      > -->
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormApply">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTeam, getTeam, delTeam, addTeam, updateTeam, exportTeam } from '@/api/eqxm/team';
import {
  listTeamStudent,
  getTeamStudent,
  delTeamStudent,
  addTeamStudent,
  updateTeamStudent,
  exportTeamStudent,
  listAdvanced,
  listCredit,
  applyCredit,
  getUserTeam,
} from '@/api/eqxm/teamStudent';
import CKEditor from 'ckeditor4-vue';
import CommonUtils from '@/utils/CommonUtils';
export default {
  name: 'Team',
  dicts:["creditStatus"],
  components: {
    ckeditor: CKEditor.component
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 团队表格数据
      teamList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        college: null,
        researchtopic: null,
        isimportant: null,
        presentation: null,
        presentationdetail: null,
        transportation: null,
        accommodation: null,
        publicity: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      recommendOptions: [],
      creditStatusOptions: [],
      // 实践积分申请对话框
      applyopen:false,
      purpose:'',
      teamOptions:[],
    };
  },
  created() {
    this.getDicts('teamstatus').then(response => {
      this.teamstatus = response.data;
    });
    this.getDicts('researchtopic').then(response => {
      this.researchtopics = response.data;
    });
    this.getDicts('isimportant').then(response => {
      this.isimportants = response.data;
    });
    this.getDicts('isimportant').then(response => {
      this.isimportants = response.data;
    });
    this.getDicts('creditStatus').then(response => {
      this.creditStatusOptions = response.data;
    });
    this.getList();
    this.getDicts('recommend').then(response => {
      this.recommendOptions = response.data;
    });
    getUserTeam().then(response => {
	  this.teamOptions = response.data;
	  // if(this.teamOptions.length>0){
		//   this.upload.college=this.teamOptions[0].college;
		  
	  // }
	});	
  },
  methods: {
    statusFormat(row, column) {
      return this.selectDictLabel(this.teamstatus, row.status);
    },
    isimportantFormat(row, column) {
      return this.selectDictLabel(this.isimportants, row.isimportant);
    },
    researchtopicFormat(row, column) {
      return this.selectDictLabel(this.researchtopics, row.researchtopic);
    },
    recommendFormat(row, column) {
      return this.selectDictLabel(this.recommendOptions, row.recommend);
    },
    creditStatusFormat(row, column) {
      return this.selectDictLabel(this.creditStatusOptions, row.creditStatus);
    },
    /** 查询团队列表 */
    getList() {
      this.loading = true;
      listCredit(this.queryParams).then(response => {
        this.teamList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.applyopen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        delFlag: null,
        college: null,
        createBy: null,
        researchtopic: null,
        isimportant: null,
        createTime: null,
        presentation: null,
        updateBy: null,
        presentationdetail: null,
        updateTime: null,
        transportation: null,
        accommodation: null,
        publicity: null,
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      //清空store的项目信息
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/team/teamManage', //跳转的路径
        query: { type: 0 },
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();

      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/credit/lookStudent/' + row.id, //跳转的路径
      });
    },
    upload(row) {
      this.reset();
      let teamInfo = {
        id: row.id,
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/team/upload', //跳转的路径
        query: { type: 0 },
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTeam(this.form).then(response => {
              if(response.code==200){
              this.$modal.msgSuccess('修改成功');
              this.open = false;
              this.getList();
              }
            });
          } else {
            addTeam(this.form).then(response => {
              if(response.code==200){
              this.$modal.msgSuccess('新增成功');
              this.open = false;
              this.getList();
              }
            });
          }
        }
      });
    },
    /** 实践积分申请提交按钮 */
    submitFormApply() {
      let subForm={};
      subForm.creditPurpose=this.purpose;
      applyCredit(subForm).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.open = false;
        this.getList();
		
		this.time="";
		 this.purpose=""
		
      });

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除团队编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(function () {
          return delTeam(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess('删除成功');
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有团队数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(function () {
          return exportTeam(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    recommendTeam() {
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatch/recommendTeam', //跳转的路径
      });
    },
    judge() {
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatch/judge', //跳转的路径
      });
    },
    review() {
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatch/review', //跳转的路径
      });
    },
    collegeScore1() {
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatch/collegeScore1', //跳转的路径
      });
    },
    goApply() {
      this.applyopen = true;
      // const vm = this;
      // vm.$router.push({
      //   //核心语句
      //   path: '/credit/apply', //跳转的路径
      // });
    },
  },
};
</script>
